package ru.urfc.portal.ui.client.renderers;

import ru.urfc.portal.ui.client.Style;
import ru.urfc.portal.ui.client.Utils;
import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.model.catalogs.CatalogItemWithStyle;
import ru.urfc.portal.ui.client.renderers.colorers.BaseColorer;
import ru.urfc.portal.ui.client.renderers.colorers.CatalogItemColorer;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public class CatalogItemRenderer extends SimpleRenderer {

	protected boolean renderForCell = false;
	
	public CatalogItemRenderer(GridField textField, GridField codeField, 
			Class<? extends CatalogItemWithStyle> klass, Element element, Style style) {
		this(textField, element, new CatalogItemColorer(textField, codeField, klass, element, style));
	}	
	
	public CatalogItemRenderer(GridField textField, Element element, BaseColorer colorer) {
		super(textField, element);
		this.colorer = colorer;
	}

	@Override
	public Object renderCell(ModelData modelData) {
		renderForCell = true;
		return super.renderCell(modelData);
	}

	@Override
	public String render(ModelData modelData) {
		String text = field.getValue(modelData);
		return text == null? "\u2014": renderForCell? Utils.decapitalize(text): Utils.capitalize(text);
	}

}
